package cases;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-21
 * Time: 20:33
 */

class MyCircularQueue{
    public int[] elem;
    public int front;
    public int rear;

    public MyCircularQueue(int key){
        this.elem = new int[key+1];
    }

    //判断队列是否为空
    public boolean isEmpty(){return front == rear;}

    //判断队列是否为满
    public boolean isFull(){
        if ((this.rear+1) % elem.length == front){
            return true;
        }
        return false;
    }

    //入队
    public void offer(int val){
        if (isFull()){
            System.out.println("队列已满");
            return;
        }
        this.elem[rear] = val;
        rear = (rear+1) % elem.length;
    }

    //出入
    public void poll(){
        if (isEmpty()){
            System.out.println("循环队列为空!");
        }
        front = (front+1) % elem.length;
    }

    //获取队首元素
    public void peek(){
        if (isEmpty()){
            System.out.println("循环队列为空");
        }
        System.out.println(elem[front]);
    }

    //获取队尾元素

}





//阻塞队列 先实现一个循环队列
public class Demo3 {

}
